<template>
  <div>
    <!-- 首页跑马灯 -->
    <el-carousel :interval="4000" type="card" height="400px">
      <el-carousel-item v-for="item in popularGoods" :key="item">
        <router-link to="/GoodsDetail"><img :src=item.showSrc @click="changeSelectedItem(item)"></router-link>
      </el-carousel-item>
    </el-carousel>
    <p>热门手机</p>
    <!-- 商品列表 -->
    <el-row :gutter="20" v-for="item in 2"  :key="item">
      <el-col :span="6" v-for="index in 4" :key="index">
        <el-card :body-style="{ padding: '0px' }">
          <router-link to="/GoodsDetail"><img :src=homeGoodList[item*index-1].src width="370" height="400" @click="changeSelectedItem(homeGoodList[item*index-1])"></router-link>
          <!-- <div height="150">
            <span>{{ homeGoodList[item*index-1].title }}</span>
            <span>{{ homeGoodList[item*index-1].description }}</span>
            <span>{{ homeGoodList[item*index-1].price }}</span>
          </div> -->
          <div class="item-Title"><span style="font-size: 26px;color: #000000;font-weight: 600;">{{ homeGoodList[item*index-1].title }}</span></div>
          <div class="item-Description"><span style="font-size: 12px;color: #000000;font-weight: 300;">{{ homeGoodList[item*index-1].description }}</span></div>
          <div class="item-Price"><span style="font-size: 25px;color: #FF0000;font-weight: 500;">{{ homeGoodList[item*index-1].price }}</span></div>
        </el-card>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import {mapGetters} from 'vuex'
export default {
  data () {
    return {}
  },
  computed: mapGetters({
    popularGoods: 'getPopularGoods',
    homeGoodList: 'getHomeGoods'
  }),
  methods: {
    changeSelectedItem (item) {
      this.$store.dispatch('changeSelectedItem', item)// 改变进入商品
    }
  }
}
</script>

<style scoped>
  .el-carousel__item h3 {
    color: #475669;
    font-size: 14px;
    opacity: 0.75;
    line-height: 200px;
    margin: 0;
  }

  .el-carousel__item:nth-child(2n) {
    background-color: #99a9bf;
  }

  .el-carousel__item:nth-child(2n+1) {
    background-color: #d3dce6;
  }
  .el-row {
    margin-bottom: 20px;
    &:last-child {
      margin-bottom: 0;
    }
  }
.item-Title {
  line-height: 40px;
  /*text-align: left;*/
  height: 40px;
  padding: 0px;
}
.item-Description {
  line-height: 40px;
  /*text-align: left;*/
  height: 40px;
  padding: 0px;
}
.item-Price {
  line-height: 40px;
  /*text-align: left;*/
  height: 40px;
  padding: 0px;
}
</style>
